import sys
import os
sys.path.insert(0, "./asteroid/")
from asteroid.models import BaseModel
from asteroid.models import ConvTasNet

os.system('rm -rf result result_new')
os.system('mkdir result result_new')

# 'from_pretrained' automatically uses the right model class (asteroid.models.DPRNNTasNet).
model = ConvTasNet.from_pretrained("JorisCos/ConvTasNet_Libri3Mix_sepclean_8k")

# Or simply a file name:
for i in range(9):
    print(i+1)
    model.separate("./noisy/combine00" + str(i+1) + ".wav", resample=True, force_overwrite=True, output_dir='./result')
print(10)
model.separate("./noisy/combine010.wav", resample=True, force_overwrite=True, output_dir='./result')


# model_new = BaseModel.from_pretrained("mpariente/ConvTasNet_Libri1Mix_enhsingle_8k")

# audio_list = os.listdir('./result')
# for audio in audio_list:
#     print(audio)
#     audio_path = os.path.join('./result', audio)
#     model_new.separate(audio_path, resample=True, force_overwrite=True, output_dir='./result_new')

# audio_list = os.listdir('./result_new')
# for audio in audio_list:
#     print(audio)
#     audio_path = os.path.join('./result_new', audio)
#     temp_path = os.path.join('./result_new', audio[7:15]+'.wav')
#     new_path = temp_path.replace('est1', 'left').replace('est2', 'middle').replace('est3', 'right')
#     os.rename(audio_path, new_path)


audio_list = os.listdir('./result')
for audio in audio_list:
    print(audio)
    audio_path = os.path.join('./result', audio)
    # temp_path = os.path.join('./result_new', audio[7:15]+'.wav')
    new_path = audio_path.replace('est1', '1').replace('est2', '2').replace('est3', '3').replace('combine', '')
    os.rename(audio_path, new_path)